import time
from retrying import retry

num = 1


# 出现错误，重试
@retry(stop_max_attempt_number=3)
def work():
    global num
    print(f"num = {num}")
    num += 1
    time.sleep(1)
    # 模拟请求失败
    for i in num:
        print(i)


try:
    work()
except Exception as e:
    print('异常为：', e)
